<template>
  <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <el-form :model="dialogModel" ref="addTaskForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="name" label="任务名称">
          <el-input v-model="dialogModel.name" clearable></el-input>
        </el-form-item>
        <el-form-item prop="taskType" label="任务类型">
          <el-select v-model="dialogModel.taskType" clearable style="width: 100%" placeholder="请选择...">
            <el-option v-for="(item, index) in dictDateType.dictItemVO" :key="item.id" :label="item.name"
              :value="item.itemValue" />
          </el-select>
        </el-form-item>
        <el-form-item prop="stages" label="阶段集合">
          <el-select v-model="dialogModel.stages" placeholder="请选择阶段" style="width: 100%" multiple>
            <el-option v-for="option in stagePageList.list" :key="option.id" :label="option.name" :value="option.id" />
          </el-select>
        </el-form-item>
        <el-form-item prop="taskBaseline" label="基线名称">
          <el-input v-model="dialogModel.taskBaseline" clearable></el-input>
        </el-form-item>
        <el-form-item prop="endTime" label="结束时间">
          <!-- <el-input v-model="dialogModel.endTime" clearable></el-input> -->
          <el-date-picker v-model="dialogModel.endTime" type="datetime" style="width: 100%" popper-class="time-picker" placeholder="请选择结束时间" />
        </el-form-item>

        <el-form-item prop="remark" label="备注">
          <el-input v-model="dialogModel.remark" clearable></el-input>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { ref ,nextTick} from 'vue'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';
import addEditModel from '@/composables/02Review/01ProjectMan/addEditModel'
import { EditType, Title } from '@/type/BaseEnum';
import { ElForm } from 'element-plus';
const { rules, dialogModel } = addEditModel()
const addTaskForm = ref<InstanceType<typeof ElForm>>();
// 使用
const emit = defineEmits(['save'])
const { dialog, onClose, onShow } = useDialog()
const { global, proxy } = useInstance();
// 父级数据
const props = defineProps({
  dictDateBaseline: {
    type: Object,
    default: () => { }
  },
  dictDateType: {
    type: Object,
    default: () => { }
  },
  stagePageList: {
    type: Object,
    default: () => { }
  }
})
// 保存

const confirm = () => {
  addTaskForm.value?.validate(isOk => {
    if (isOk) {
      emit('save', dialogModel)
      onClose()
    }
  })
}
const show = (type: string, row?: any) => {
  console.log('show');
  dialog.width = 650
  dialog.height = 300
  dialog.title = type == EditType.ADD ? Title.ADD : Title.EDIT
  onShow()
// bug
  global.$resetForm(addTaskForm.value, dialogModel)
  dialogModel.stages=[]
  if (type === EditType.EDIT) {
    global.$objCopy(row, dialogModel)
  }

}
defineExpose({
  show
})
</script>
<style lang='scss'>
.time-picker{
  .el-picker-panel__body{
    .el-date-picker__time-header{

      .el-date-picker__editor-wrap{
        .el-input__inner{
            color: #000 !important;
        }
      }
    }
  }
}
</style>